package com.javalab._7thread._5ThreadPool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class _04ScheduledThreadPool {
    public static void main(String[] args) {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(5);
        executor.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("延迟10秒执行...");
            }
        },10, TimeUnit.SECONDS);

        executor.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("程序启动后10秒执行第一次，每隔5秒执行一次");
            }
        },10,5,TimeUnit.SECONDS);

        executor.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                System.out.println("程序启动后10秒执行第一次，等上一个任务完成后5秒执行");
            }
        },10,5,TimeUnit.SECONDS);
    }
}
